import axios from "axios";

const instance = axios.create({
  baseURL: "https://baidu.com",
  timeout: 5000,
});

instance.interceptors.request.use(
  (config) => {
    config.headers = {
      "content-type": "application/x-www-form-urlencoded",
    };

    config.transformRequest = [
      function(data) {
        let ret = "";
        for (let it in data) {
          ret += encodeURIComponent(it) + "=" + encodeURIComponent(data[it]) + "&";
        }
        return ret;
      },
    ];
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

instance.interceptors.response.use(
  (res) => {
    return res;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default instance;
